/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.ctrl;

import com.cxhd.lis.model.newmodel.ZkReagentumber;
import static com.cxhd.lis.model.newmodel.ZkReagentumber.zkReagentumberDao;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;

/**
 *
 * @author cxhd
 */
@ControllerBind(controllerKey = "/view/lis/zkreagent")
public class ZkReagentumberCtrl extends Controller{
     public void index(){
        render("/view/lis/zk_reagentumber.jsp");
    }
    
     public void getZkReagents(){
          String sql="select  PK,REAGENTNUMBER,EXFACTORY,REAGENTNAME ";
          String param="from zk_reagentumber where REAGENTNUMBER like '%"+getPara("searchContent")+"%' or EXFACTORY like '%"+getPara("searchContent")+"%'";
       Page<Record> userPage =Db.use("mysql").paginate(getParaToInt("currentPage",getParaToInt("currentPage")), getParaToInt("pageSize",getParaToInt("pageSize")), sql, param);
       renderJson(userPage);
     }
     public void getZkReagentRep(){
           List<Record> list= Db.use("mysql").find("select * from zk_reagentumber where REAGENTNUMBER=?",getPara("REAGENTNUMBER"));
       if(list.size()!=0){ 
            if(getPara("PK")!=""&&getPara("PK")!=null){//判断是新增还是修改
                if(Integer.valueOf(getPara("PK"))==list.get(0).get("PK")){ //修改是允许修改（本身主键和查询到的主键相同）
                     renderText("false");
                }else{
                   renderText("true");  
                }
            }else{
                renderText("true");
            }
        
        }else{
            renderText("false");
        }
     }
     public void deleteZkReagent(){
         try{
         new ZkReagentumber().deleteReagent(getPara("PK"));
         }catch( Exception e){
            renderJson("false");
         }
         renderJson("true");
         
     }
     public void saveZkReagent(){
         new ZkReagentumber().saveZkReagent(this);
         renderText("true");
     }
     public void updateZkReagent(){
         zkReagentumberDao.updateZkReagent(this);
        renderText("true");
     }
}
